<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jspf"%>
<es:contentHeader />
<%@include file="/WEB-INF/jsp/common/import-upload-css.jspf"%>
<div class="panel">

	<ul class="nav nav-tabs">
		<shiro:hasPermission name="vip:business:create">
			<c:if test="${op eq '新增'}">
				<li ${op eq '新增' ? 'class="active"' : ''}><a
					href="${ctx}/vip/business/create?BackURL=<es:BackURL/>"> <i
						class="icon-file-alt"></i> 新增
				</a></li>
			</c:if>
		</shiro:hasPermission>

		<c:if test="${not empty m.id}">
			<li ${op eq '查看' ? 'class="active"' : ''}><a
				href="${ctx}/vip/business/${m.id}?BackURL=<es:BackURL/>"> <i
					class="icon-eye-open"></i> 查看
			</a></li>
			<shiro:hasPermission name="vip:business:update">
				<li ${op eq '修改' ? 'class="active"' : ''}><a
					href="${ctx}/vip/business/${m.id}/update?BackURL=<es:BackURL/>">
						<i class="icon-edit"></i> 修改
				</a></li>
			</shiro:hasPermission>

			<shiro:hasPermission name="vip:business:delete">
				<li ${op eq '删除' ? 'class="active"' : ''}><a
					href="${ctx}/vip/business/${m.id}/delete?BackURL=<es:BackURL/>">
						<i class="icon-trash"></i> 删除
				</a></li>
			</shiro:hasPermission>
		</c:if>
		<li><a href="<es:BackURL/>" class="btn btn-link"> <i
				class="icon-reply"></i> 返回
		</a></li>
	</ul>

	<form:form id="editForm" method="post" commandName="m"
		cssClass="form-horizontal">
		<!--上一个地址 如果提交方式是get 需要加上-->
		<%--<es:BackURL hiddenInput="true"/>--%>

		<es:showGlobalError commandName="m" />

		<form:hidden path="id" />

		<div class="control-group">
			<form:label path="bsName" cssClass="control-label">商家名称</form:label>
			<div class="controls">
				<form:input path="bsName"
					cssClass="input-xxlarge validate[required,ajax[ajaxNameCall]]"
					placeholder="5到10个字母、数字、下划线" />
			</div>
		</div>

		<div class="control-group">
			<label for="files" class="control-label">商家LOGO</label>
			<div class="controls">
				<label for="files" class="btn btn-success fileinput-button">
					<i class="icon-plus icon-white"></i> <span>添加文件...</span> <input
					type="file" id="files" name="files[]" data-url="${ctx}/ajaxUpload"
					multiple>
				</label> <span class="help-inline">（仅支持图片文件格式）</span>
			</div>
		</div>
		
		<div class="control-group"
			style="margin-bottom: 0px;<c:if test="${empty m.bsLogo}">display: none</c:if>">
			<label for="files" class="control-label"></label>
			<div class="controls">
				<c:if test="${not empty m.bsLogo}">
					<es:showAttachment filename="${m.bsLogo}" showImage="true"
						width="80%" height="100" />
				</c:if>
				<div class="ajax-upload-view"></div>
				<form:hidden path="bsLogo" />
			</div>
		</div>

		<div class="control-group">
			<form:label path="businessType.id" cssClass="control-label">商家类型</form:label>
			<div class="controls">
				<form:select path="businessType.id" cssClass="validate[required]">
					<form:option value="">选择类型</form:option>
					<form:options items="${businessType}" itemValue="id"
						itemLabel="typeName" />
				</form:select>
			</div>
		</div>

		<div class="control-group">
			<form:label path="bsAddress" cssClass="control-label">商家地址</form:label>
			<div class="controls">
				<form:input path="bsAddress"
					cssClass="input-xxlarge validate[required]" placeholder="请输入商家地址" />
			</div>
		</div>

		<div class="control-group">
			<form:label path="bsTell" cssClass="control-label">商家电话</form:label>
			<div class="controls input-append">
				<form:input path="bsTell" cssClass="validate[required]"
					placeholder="请输入商家电话信息" />
			</div>
		</div>

		<div class="control-group">
			<form:label path="bsConsume" cssClass="control-label">人均消费</form:label>
			<div class="controls input-append">
				<form:input path="bsConsume" cssClass="validate[required]"
					placeholder="请输入人均消费信息" />
			</div>
		</div>
		<div class="control-group">
			<form:label path="bsEnvironmental" cssClass="control-label">环境打分</form:label>
			<div class="controls input-append ">
				<div id="bsEnvironmental"></div>
				<form:hidden path="bsEnvironmental" />
			</div>
		</div>
		<div class="control-group">
			<form:label path="bsEffect" cssClass="control-label">效果打分</form:label>
			<div class="controls input-append">
				<div id="bsEffect"></div>
				<form:hidden path="bsEffect" />
			</div>
		</div>
		<div class="control-group">
			<form:label path="bsServe" cssClass="control-label">服务打分</form:label>
			<div class="controls input-append ">
				<div id="bsServe"></div>
				<form:hidden path="bsServe" />
			</div>
		</div>
		<div class="control-group">
			<form:label path="bsGread" cssClass="control-label">星级打分</form:label>
			<div class="controls input-append">
				<div id="bsGread"></div>
				<form:hidden path="bsGread" />
			</div>
		</div>
		<div class="control-group">
			<form:label path="show" cssClass="control-label">是否显示</form:label>
			<div class="controls inline-radio">
				<form:radiobuttons path="show" items="${booleanList}"
					itemLabel="info" itemValue="value" cssClass="validate[required]" />
			</div>
		</div>

		<c:if test="${op eq '新增'}">
			<c:set var="icon" value="icon-file-alt" />
		</c:if>
		<c:if test="${op eq '修改'}">
			<c:set var="icon" value="icon-edit" />
		</c:if>
		<c:if test="${op eq '删除'}">
			<c:set var="icon" value="icon-trash" />
		</c:if>

		<div class="control-group">
			<div class="controls">
				<button type="submit" class="btn btn-primary">
					<i class="${icon}"></i> ${op}
				</button>
				<a href="<es:BackURL/>" class="btn"> <i class="icon-reply"></i>
					返回
				</a>
			</div>
		</div>


	</form:form>
</div>

<es:contentFooter />
<%@include file="/WEB-INF/jsp/common/import-upload-simple-js.jspf"%>
<%@include file="/WEB-INF/jsp/common/import-raty-js.jspf"%>
<script type="text/javascript">
	$(function() {
		$('.fileinput-button input[type="file"]').fileupload({
			dataType : "json"
		});
		$('.fileinput-button input[type="file"]')
				.fileupload(
						"option",
						{
							progressall : function(e, data) {
								var view = $(".ajax-upload-view");
								view.parent().parent().show();
								var progressBar = view.find(".progress");
								if (progressBar.size() == 0) {
									var progressBarTemplate = '<div class="progress progress-striped">'
											+ '<div class="bar"></div>' + '</div>';
									progressBar = view.append(progressBarTemplate);
								}
								var progress = parseInt(data.loaded / data.total * 100, 10);
								progressBar.find(".bar").css("width", progress + "%");
							},
							start : function(e) {
								$(".ajax-upload-view").html("");
								var submitBtn = $(this).closest("form").find(":submit");
								submitBtn.data("value", submitBtn.val()).val("上传文件中...").prop("disabled", true);
							},
							//上传完成
							done : function(e, data) {
								$
										.each(
												data.result.files,
												function(index, file) {
													if (file.error) {
														$(".ajax-upload-view").html(
																"<div class='alert alert-error'>" + file.error
																		+ "</div>");
													} else {
														$("[name='bsLogo']").val(file.url);
														var msg = "<div class='alert alert-success'><strong>上传成功！</strong><br/>{preview}</div>";
														var preview = "";
														var url = ctx + "/" + file.url;
														var thumbnail_url = ctx + "/" + file.thumbnail_url;
														if ($.app.isImage(file.name)) {
															preview = "<a href='{url}' target='_blank'><img src='{thumbnail_url}' title='{name}' height='120px'/></a>"
														} else {
															preview = "<a href='{url}' target='_blank'>{name}</a>"
														}
														preview = preview.replace("{url}", url).replace(
																"{thumbnail_url}", thumbnail_url).replace("{name}",
																file.name);
														msg = msg.replace("{preview}", preview);
														$(".ajax-upload-view").html(msg);

													}
												});
								var submitBtn = $(this).closest("form").find(":submit");
								submitBtn.val(submitBtn.data("value")).prop("disabled", false);
							}
						});
		<c:choose>
		<c:when test="${op eq '删除'}">
		//删除时不验证 并把表单readonly
		$.app.readonlyForm($("#editForm"), false);
		</c:when>
		<c:when test="${op eq '查看'}">
		$.app.readonlyForm($("#editForm"), true);
		</c:when>
		<c:otherwise>
		//自定义ajax验证  ajax[ajaxNameCall] 放到验证规则的最后（放到中间只有当submit时才验证）
		$.validationEngineLanguage.allRules.ajaxNameCall = {
			"url" : "${ctx}/vip/business/validate",
			//动态提取的数据。验证时一起发送
			extraDataDynamic : [ '#id' ],
			//验证失败时的消息
			//"alertText": "* 该名称已被其他人使用",
			//验证成功时的消息
			//"alertTextOk": "该名称可以使用",
			"alertTextLoad" : "* 正在验证，请稍等。。。"
		};
		var validationEngine = $("#editForm").validationEngine();
		<es:showFieldError commandName="m"/>
		</c:otherwise>
		</c:choose>
		//raty
		$('#bsGread').raty({
			<c:if test="${op ne '新增'}">
			readOnly:  true,
			start:     ${m.bsGread},
			</c:if>
			path : '${ctx}/static/comp/jquery-raty/img',
			scoreName : 'bsGread',
			number : 10
		});
		$('#bsServe').raty({
			<c:if test="${op ne '新增'}">
			readOnly:  true,
			start:      ${m.bsServe},
			</c:if>
			path : '${ctx}/static/comp/jquery-raty/img',
			scoreName : 'bsServe',
			number : 10
		});
		$('#bsEffect').raty({
			<c:if test="${op ne '新增'}">
			readOnly:  true,
			start: ${m.bsEffect},
			</c:if>
			path : '${ctx}/static/comp/jquery-raty/img',
			scoreName : 'bsEffect',
			number : 10
		});
		$('#bsEnvironmental').raty({
			<c:if test="${op ne '新增'}">
			readOnly:  true,
			start:  ${m.bsEnvironmental},
			</c:if>
			path : '${ctx}/static/comp/jquery-raty/img',
			scoreName : 'bsEnvironmental',
			number : 10
		});

	});
</script>